<?php
namespace app\decorate\controller;
use app\AdminRest;
use app\ApiRest;
use longbingcore\wxcore\WxSetting;
use think\App;
use think\Request;
use app\decorate\model\AdminDynamic as dyn_model;
use app\decorate\model\IndexSite;


class IndexDynamic extends ApiRest{
    protected $model;
    protected $site_model;
    public function __construct(App $app) {
        parent::__construct($app);
        $this->model      = new dyn_model();
        $this->site_model = new IndexSite();
    }
    /**
     * User: chenniang
     * Date: 2019-10-09 15:58
     * @return \think\Response
     * descption:动态列表
     */
    public function dynList(){
        $input = $this->_param;
        $dis[] = ['a.uniacid','=',$this->_uniacid];
        $dis[] = ['a.staff_id','=',$input['staff_id']];
        $data  = $this->model->dynList($dis,10);
        return $this->success($data);
    }

    /**
     * User: chenniang
     * Date: 2019-10-23 15:38
     * @return void
     * descption:发动态
     */
    public function dynAdd(){
        $input = $this->_input;

        $core  = new WxSetting($this->_uniacid);

        if(isset($input['content'])){

            $rest = $core->wxContentRlue($input['content']);

            if($rest['errcode'] != 0){

                return $this->error('内容含有违法违规内容');
            }

        }

        $input['uniacid'] = $this->_uniacid;
        $progerss = $this->site_model->where(['id'=>$input['site_id']])->value('progress');
        $input['progress'] = $progerss;
        $input['imgs']     = !empty($input['imgs'])?implode(',',$input['imgs']):'';
        $res = $this->model->dynAdd($input);
        return $this->success($res);
    }
    /**
     * User: chenniang
     * Date: 2019-10-09 15:59
     * @return \think\Response
     * descption:s删除动态
     */
    public function dynDel(){
        $input = $this->_input;
        $data = $this->model->dynUpdate(['id'=>$input['id']],['status'=>-1]);
        return $this->success($data);
    }








}
